using System;

namespace NUnit.Behave
{
    public class GivenContext : Context
    {
        private WhenContext whenContext;

        public GivenContext() : this(new WhenContext())
        {
        }

        public GivenContext(WhenContext whenContext)
        {
            this.whenContext = whenContext;
            singleMessageType = MessageType.Given;
            singleMessageTypePending = MessageType.Given_Pending;
            conjunctionMessageType = MessageType.Given_And;
            conjunctionMessageTypePending = MessageType.Given_And_Pending;
        }

        public GivenContext Add_AddVerb<T>(string givenMessage, T actionValue)
        {
            return EvaluateMessageForCatalogEntry(this, givenMessage, actionValue, MessageType.Given_Pending);
        }

        public GivenContext And<T>(string givenMessage, T actionValue)
        {
            return EvaluateMessageForCatalogEntry(this, givenMessage, actionValue, MessageType.Given_And_Pending);
        }

        public GivenContext Add_AddVerb<T>(string givenMessage, T actionValue, Action<T> delegateAction)
        {
            return EnvokeActionAndStoreForLaterUse(this, actionValue, delegateAction, givenMessage, MessageType.Given);
        }

        public GivenContext And<T>(string givenMessage, T actionValue, Action<T> delegateAction)
        {
            return
                EnvokeActionAndStoreForLaterUse(this, actionValue, delegateAction, givenMessage, MessageType.Given_And);
        }

        public WhenContext When<T>(string whenMessage, T actionValue)
        {
            whenContext.Add_AddVerb(whenMessage, actionValue);

            return whenContext;
        }

        public WhenContext When<T>(string whenMessage, T actionValue, Action<T> delegateAction)
        {
            whenContext.Add_AddVerb(whenMessage, actionValue, delegateAction);

            return whenContext;
        }

        protected override void PassToNextProvider(IMessageProvider provider)
        {
            whenContext.RenderTo(provider);
        }
    }
}